package com.ruoyi.web.controller.operation;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alipay.api.AlipayApiException;
import com.ruoyi.system.domain.vo.PlatformRightsOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GwPlatformRightsOrder;
import com.ruoyi.system.service.IGwPlatformRightsOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 平台权益订单Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@Api(description = "平台运营管理-平台权益订单")
@RestController
@RequestMapping("/system/platformRightsOrder")
public class GwPlatformRightsOrderController extends BaseController
{
    @Autowired
    private IGwPlatformRightsOrderService gwPlatformRightsOrderService;

    /**
     * 查询平台权益订单列表
     */
    @ApiOperation("查询平台权益订单列表-分页")
    @GetMapping("/list")
    public TableDataInfo list(GwPlatformRightsOrder gwPlatformRightsOrder)
    {
        startPage();
        List<PlatformRightsOrderVO> list = gwPlatformRightsOrderService.selectList(gwPlatformRightsOrder);
        return getDataTable(list);
    }

    /**
     * 导出平台权益订单列表
     */
//    @PreAuthorize("@ss.hasPermi('system:platformRightsOrder:export')")
    @Log(title = "平台权益订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GwPlatformRightsOrder gwPlatformRightsOrder)
    {
        List<GwPlatformRightsOrder> list = gwPlatformRightsOrderService.selectGwPlatformRightsOrderList(gwPlatformRightsOrder);
        ExcelUtil<GwPlatformRightsOrder> util = new ExcelUtil<GwPlatformRightsOrder>(GwPlatformRightsOrder.class);
        util.exportExcel(response, list, "平台权益订单数据");
    }

    /**
     * 获取平台权益订单详细信息
     */
    @ApiOperation("获取平台权益订单详情")
//    @PreAuthorize("@ss.hasPermi('system:platformRightsOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(gwPlatformRightsOrderService.selectGwPlatformRightsOrderById(id));
    }

    /**
     * 新增平台权益订单
     */
    @ApiOperation("新增平台权益订单")
//    @PreAuthorize("@ss.hasPermi('system:platformRightsOrder:add')")
    @Log(title = "平台权益订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GwPlatformRightsOrder gwPlatformRightsOrder)
    {
        return toAjax(gwPlatformRightsOrderService.insertGwPlatformRightsOrder(gwPlatformRightsOrder));
    }

    /**
     * 修改平台权益订单
     */
    @ApiOperation("修改平台权益订单")
//    @PreAuthorize("@ss.hasPermi('system:platformRightsOrder:edit')")
    @Log(title = "平台权益订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GwPlatformRightsOrder gwPlatformRightsOrder)
    {
        return toAjax(gwPlatformRightsOrderService.updateGwPlatformRightsOrder(gwPlatformRightsOrder));
    }

    /**
     * 删除平台权益订单
     */
    @ApiOperation("删除平台权益订单")
//    @PreAuthorize("@ss.hasPermi('system:platformRightsOrder:remove')")
    @Log(title = "平台权益订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(gwPlatformRightsOrderService.deleteGwPlatformRightsOrderByIds(ids));
    }

    /**
     * PC端购买套餐
     */
    @ApiOperation("PC端扫描支付订单")
    @Log(title = "平台权益订单", businessType = BusinessType.INSERT)
    @PostMapping("/payOrder")
    public AjaxResult payOrder(@RequestBody GwPlatformRightsOrder gwPlatformRightsOrder) throws AlipayApiException {
        return gwPlatformRightsOrderService.payOrder(gwPlatformRightsOrder);
    }

    /**
     * 微信小程序购买套餐
     */
    @ApiOperation("微信小程序支付订单")
    @Log(title = "平台权益订单", businessType = BusinessType.INSERT)
    @PostMapping("/applet/payOrder")
    public AjaxResult appletPayOrder(@RequestBody GwPlatformRightsOrder gwPlatformRightsOrder) throws IOException {
        return gwPlatformRightsOrderService.appletPayOrder(gwPlatformRightsOrder);
    }

    /**
     * 查询平台权益订单列表
     */
    @ApiOperation("查询平台权益订单列表-分页")
    @GetMapping("/orderList")
    public TableDataInfo orderList(GwPlatformRightsOrder gwPlatformRightsOrder)
    {
        startPage();
        List<PlatformRightsOrderVO> list = gwPlatformRightsOrderService.orderList(gwPlatformRightsOrder);
        return getDataTable(list);
    }

}
